package com.smallpineapple.turing.service.guest.impl;

import com.smallpineapple.turing.dao.ProjectDao;
import com.smallpineapple.turing.entity.Project;
import com.smallpineapple.turing.enums.MyCustomizeErrorCode;
import com.smallpineapple.turing.exception.CustomizeException;
import com.smallpineapple.turing.service.guest.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Jack
 * @date 2019-06-27-17:37
 */
@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    ProjectDao projectDao;

    @Override
    public Project findProjectById(Long id) {

        Project project = projectDao.findById(id).get();
        if(project == null){
            throw new CustomizeException(MyCustomizeErrorCode.PROJECT_NOT_FOUND);
        }
        return project;

    }

    @Override
    public List<Project> findAllProjects() {

        List<Project> projects = projectDao.findAll();
        return projects;

    }
}
